﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;


namespace WizzardTheGame
{
    class Camera
    {
        private static Vector3 LOOKAT_CAMERA_OFFSET = new Vector3(0, 50f, -100f);
        private Vector3 position;
        private Vector3 rotation;
        private Object3D lookAt;
        private Matrix viewMatrix;
        private Matrix projectionMatrix;
        private CameraType currentCameraType;

        public enum CameraType
        {
            lookAt
        }

        #region Properties

        public Vector3 Position { 
            get { return position; } 
            set { position = value; } 
        }

        public Vector3 Rotation { 
            get { return rotation; } 
            set { rotation = value; } 
        }

        public Object3D LookAt{
            get { return lookAt; }
            set
            {
                lookAt = value;
                Position = lookAt.Position + LOOKAT_CAMERA_OFFSET;
            }
        }

        public Matrix ViewMatrix {
            get { return viewMatrix; }
            set { viewMatrix = value; }
        }

        public Matrix ProjectionMatrix {
            get { return projectionMatrix; }
            set { projectionMatrix = value; }
        }

        public CameraType CurrentCameraType {
            get { return currentCameraType; }
            set { currentCameraType = value; }
        }

        #endregion

        public Camera()
        {
        }

        public void DefaultCamera()
        {
            CurrentCameraType = CameraType.lookAt;
            GameWorld gw = GameWorld.getInstance();
            LookAt = gw.Player.CharModel;
            ViewMatrix = Matrix.CreateLookAt(Position, LookAt.Position, Vector3.Up);
            ProjectionMatrix = Matrix.CreatePerspectiveFieldOfView(MathHelper.ToRadians(45.0f),
               gw.Graphics.Viewport.AspectRatio, 1.0f, 10000.0f);
        }

        public void Update()
        {
            Position = lookAt.Position + LOOKAT_CAMERA_OFFSET;
            ViewMatrix = Matrix.CreateLookAt(Position, LookAt.Position, Vector3.Up);
        }

    }
}